package com.nintendo.bubblechat.controller;

import com.nintendo.bubblechat.entity.dto.CircleOfFriendsDTO;
import com.nintendo.bubblechat.entity.pojo.CircleComment;
import com.nintendo.bubblechat.entity.pojo.CircleOfFriends;
import com.nintendo.bubblechat.exceptions.GraceException;
import com.nintendo.bubblechat.grace.result.GraceJsonRequest;
import com.nintendo.bubblechat.service.CircleOfFriendsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/circleOfFriends")
@Slf4j
public class CircleOfFriendsController {
    @Autowired
    private CircleOfFriendsService circleOfFriendsService;
    @PostMapping("/create")
    public GraceJsonRequest createUp(@RequestBody CircleOfFriendsDTO circleOfFriendsDTO){
        System.out.println("ci====>"+circleOfFriendsDTO);
        circleOfFriendsService.createUp(circleOfFriendsDTO);
        return GraceJsonRequest.ok();
    }
    @PostMapping("/uploadFile")
    public GraceJsonRequest uploadFile(@RequestParam("file")MultipartFile file,
                                       @RequestParam("userId")String userId,
                                       @RequestParam("circleId")String circleId){
        String cId = circleOfFriendsService.uploadFile(file, userId, circleId);
        return GraceJsonRequest.ok(cId);
    }
    @PostMapping("/findCircleOfFriendsBy")
    public GraceJsonRequest findCircleOfFriendsBy(){
        List<CircleOfFriends> circleOfFriends = circleOfFriendsService.findCircleOfFriendsBy();
        return GraceJsonRequest.ok(circleOfFriends);
    }
    @PostMapping("/findMyCircleOfFriends")
    public GraceJsonRequest findMyCircleOfFriends(@RequestParam("myId")String myId){
        List<CircleOfFriends> circleOfFriends = circleOfFriendsService.findMyCircleOfFriends(myId);
        return GraceJsonRequest.ok(circleOfFriends);
    }
    @PostMapping("/thumbCircle")
    public GraceJsonRequest thumbCircle(@RequestParam("circleId")String circleId,
                                        @RequestParam("userId")String userId){
        circleOfFriendsService.thumbCircle(circleId, userId);
        return GraceJsonRequest.ok();
    }
    @PostMapping("/cancelThumbCircle")
    public GraceJsonRequest cancelThumbCircle(@RequestParam("circleId")String circleId,
                                              @RequestParam("userId")String userId){
        circleOfFriendsService.cancelThumbCircle(circleId, userId);
        return GraceJsonRequest.ok();
    }
    @PostMapping("/bindComment")
    public GraceJsonRequest bindComment(@RequestBody CircleComment circleComment){
        circleOfFriendsService.bindComment(circleComment);
        return GraceJsonRequest.ok();
    }
}
